﻿using System.Security.Cryptography;

namespace Avalon.Core.Providers
{
    public static class EncriptionProvider
    {
        private const string _passwordSalt = "00223_lkjasdlkj*&^nmasd_.._46jkamjnnn_qjweu.01";

        public static byte[] EncryptPassword(byte[] password)
        {
            SHA1 sha = new SHA1CryptoServiceProvider();

            var saltHash = sha.ComputeHash(getBytes(_passwordSalt));
            var pwHash = sha.ComputeHash(password);

            byte[] result = new byte[saltHash.Length + pwHash.Length];
            pwHash.CopyTo(result, 0);
            saltHash.CopyTo(result, pwHash.Length);

            return sha.ComputeHash(result);
        }

        public static byte[] EncryptPassword(string password)
        {
            return EncryptPassword(getBytes(password));
        }

        private static byte[] getBytes(string str)
        {
            byte[] bytes = new byte[str.Length * sizeof(char)];
            System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;
        }
    }
}
